/**
 *
 */
package org.restorator.dao.base;

import org.restorator.exception.DataStoreException;

import java.io.Serializable;
import java.util.List;

/**
 * Super interface for dao level.
 *
 * E - entity class
 * ID - entity primary key
 *
 * @author Snisar Bogdan
 */
public interface GenericDao <E, ID extends Serializable> {
    /**
     * Return entity by his id.
     * @param id Entity id.
     * @return new entity.
     */
    E get(ID id) throws DataStoreException;

    /**
     * Update entity from given example.
     *
     * @param persistElement entity example.
     * @return
     * @throws DataStoreException 
     */
    E update(E persistElement) throws DataStoreException;

    /**
     * Delete entity from storage.
     * @param deleted entity for deleting.
     */
    void delete(E deleted) throws DataStoreException;

    /**
     * Equals to sql COUNT.
     * @return number of rows
     */
    long count();

    /**
     * Insert new entity in storage.
     * @param persist entity for saving
     * @return primary key of the element
     */
    ID save(E persist, Object... addParams) throws DataStoreException;

    /**
     * Get all entity's from storage as a paramList.
     * @return {@link List} paramList of elements
     */
    List<E> getAll() throws DataStoreException;

    /**
     * Check if there is some entity with this primary key.
     * @param id entity primary key
     * @return true if there is some entity with this pk
     */
    boolean exist(ID id);

}
